package equals;

public class Animal {
     int age;
     String name;

     public Animal(String name) {
          this.name = name;
     }

     @Override
     public boolean equals (Object o) {
          if (o == null) {
               return false;
          } else if (this == o) {  // this 指代的是调用该方法的对象
               return true;
          } else if (!(o instanceof Animal)){
               return false;
          }

          Animal tmp = (Animal)o;
          return this.name.equals(tmp.name);
     }

}

class dogge {
     public static void main(String[] args) {
          Animal animal1 = new Animal("Matty");
//          Animal animal2 = new Animal("Lyh");
          Animal animal2 = new Animal("Matty");

          System.out.println(animal2.equals(animal1));
     }
}
